package com.wyp168.leetcode.entity;

/**
 * @ClassName Move
 * @Title TODO
 * @Description TODO
 * @Author wyp168
 * @Date 2022/10/10 20:02
 */
public class Move {
    public static void main(String[] args) {
        Move solution = new Move();
        int[] nums = {2,0,4,0,7,0};
        int[] result = solution.moveTo(nums);
        for (int i : result) {
            System.out.println(i);
        }
    }

    public int[] moveTo(int[] nums) {
        int left = 0, right = nums.length - 1;

        while (left < nums.length) {
            while (nums[left] == 0) {
                left ++;
                if (left == nums.length) {
                    return nums;
                }
            }
            while (nums[right] != 0) {
                right --;
            }
            int temp = nums[left];
            nums[left] = nums[right];
            nums[right] = temp;
        }
        return nums;
    }
}
